<template>
  <div class="page-container">
    <SearchPanel @change="handleSearchPanelChange">
      <el-form
        ref="queryForm"
        class="query-more-form"
        size="mini"
        label-width="100px"
        :model="query"
      >
        <el-row :gutter="21">
          <el-col :span="5">
            <el-form-item label="来源名称">
              <el-input
                v-model="query.sourceName"
                class="search-ipt"
                placeholder="请输入来源名称"
                maxlength="255"
              />
            </el-form-item>
          </el-col>
          <el-col :span="3" class="btn-col">
            <el-button size="mini" class="search-btn" @click="changeSource"
              >选择来源</el-button
            >
          </el-col>
          <el-col :span="10">
            <el-form-item label="时间区间">
              <el-date-picker
                v-model="query.startTime"
                type="datetimerange"
                size="mini"
                range-separator="-"
                start-placeholder="开始"
                end-placeholder="结束"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4" class="btn-col">
            <el-button size="mini" class="search-btn" @click="select"
              >查询</el-button
            >
          </el-col>
        </el-row>
      </el-form>
    </SearchPanel>
    <div class="table-container">
      <div class="table-tools-panel table-flex-row">
        <div class="table-btns-left">
          <el-button class="flush-btn" icon="el-icon-refresh" @click="refresh"
            >刷新</el-button
          >
        </div>
        <div>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-set-up"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-share"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-printer"
          ></el-button>
        </div>
      </div>
      <div class="table-list-panel">
        <el-table
          :data="tableData"
          style="width: 100%; margin-bottom: 20px"
          row-key="sourceName"
          :height="isShow ? 'calc(100vh - 450px)' : 'calc(100vh - 335px)'"
          border
          :default-expand-all="false"
          :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        >
          <el-table-column
            prop="sourceName"
            label="部门名称"
            sortable
            width="180"
          >
          </el-table-column>
          <el-table-column prop="bls" label="办理数"> </el-table-column>
          <el-table-column prop="aqbls" label="按期办理数"> </el-table-column>
          <el-table-column prop="csbls" label="超期办理数"> </el-table-column>
          <el-table-column prop="cswbl" label="超期未办理数"> </el-table-column>
        </el-table>
      </div>
    </div>

    <StatisticsDialog
      :dialogVisible="dispatchDialogVisible"
      @closeDialog="dispatchDialogVisible = false"
      @statisticsData='statisticsData'
    />
  </div>
</template>

<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import StatisticsDialog from "./components/statisticsDialog";
import { sourceStatistics } from "@/api/system/doubleRandomMatters";

export default {
  components: {
    SearchPanel,
    Pagination,
    StatisticsDialog,
  },
  data() {
    return {
      visible: false,
      query: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        startTime: "",
        sourceName: "",
      },
      tableLoading: false,
      dispatchDialogVisible: false,
      tableData: [],
      department: [],
      isShow: true,
      obj: {},
      defaultProps: {
        children: "children",
        label: "sourceName",
      },
    };
  },
  created() {
    this.initData();
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    initData() {
      this.select();
    },
    statisticsData(val){
      this.query.sourceName=val
    },
    changeSource() {
      this.dispatchDialogVisible = true;
      let Statistics={
        title:'来源统计',
        // data:this.tableData
      }
      this.$bus.$emit('Statistics',Statistics);
    },
    select() {
      // 数据加载提示
      // const query = JSON.parse(JSON.stringify(this.query));
      if (this.query.startTime.length > 0) {
        this.query.beginTime = this.query.startTime[0].getTime() / 1000;
        this.query.endTime = this.query.startTime[1].getTime() / 1000;
      }

      this.tableLoading = true;
      sourceStatistics(this.query)
        .then((result) => {
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData = result.data;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
    // 刷新页面
    refresh() {
      this.query = {
        total: 1,
        pageNum: 1,
        pageSize: 10,
        startTime: "",
        sourceName: "",
      };
      this.select();
    },
  },
};
</script>

<style lang="scss" scoped>
</style>